package com.chushouya.manager.service.admin.impl;


import com.chushouya.common.dto.OperateLogDTO;
import com.chushouya.manager.dao.entity.OperateLogEntity;
import com.chushouya.manager.dao.repository.OperateLogRepository;
import com.chushouya.manager.dto.admin.log.OperateLogListDTO;
import com.chushouya.manager.dto.admin.log.OperateLogQueryDTO;
import com.chushouya.manager.service.admin.OperateLogService;
import com.general.framework.core.lang.Beans;
import com.general.framework.core.schema.PageResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 操作日志
 */
@Service
@Slf4j
public class OperateLogServiceImpl implements OperateLogService {

    @Resource
    private OperateLogRepository operateLogRepository;

    @Override
    public void clean(Integer cleanBeforeDays) {
        operateLogRepository.clean(cleanBeforeDays);
    }

    @Override
    public PageResult<OperateLogListDTO> selectPageResult(OperateLogQueryDTO query) {
        return PageResult.of(operateLogRepository.selectPageResult(query), OperateLogListDTO.class);
    }

    @Override
    @Async
    public void saveOperateLog(OperateLogDTO logData) {
        OperateLogEntity operateLog = Beans.copy(logData, OperateLogEntity.class);
        operateLogRepository.saveOperateLog(operateLog);
    }
}
